using System;
using QAssetBundle;
using UnityEngine;
using QFramework;

namespace ProjectSurvival
{
	public partial class Coin : PowerUp
	{
		private Collider2D _collider;

		private void Awake()
		{
			_collider = GetComponent<Collider2D>();
		}

		void Start()
		{
			gameObject.OnTriggerEnter2DEvent((other) =>
			{
				if (other.GetComponent<CollectableArea>())
				{
					FlyToPlayer = true;
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
		}

		protected override Collider2D Collider => _collider;
		protected override void Execute()
		{
			AudioKit.PlaySound(Coin_wav.Coin);
			Global.Coin.Value++;
			gameObject.DestroySelfGracefully();
		}
	}
}
